/*******************************************************************************
 *
 *      Filename: Controller.h
 *   Description: Keyboard and Mouse conroller classes
 *        Author: [kb]ypp
 *    Created at: November 20, 2005
 * Last modified: 
 *
 ******************************************************************************/

#ifndef CONTROLLER_H
#define CONTROLLER_H

#include "Singleton.h"

class Keyboard : public Singleton< Keyboard > {
public:
	enum Key {
		KEY_NONE = 256,
		KEY_ESCAPE,
		KEY_TAB,
		KEY_CAPS_LOCK,
		KEY_ENTER,
		KEY_BACKSPACE,
		KEY_LSHIFT,
		KEY_RSHIFT,
		KEY_LCONTROL,
		KEY_RCONTROL,
		KEY_LALT,
		KEY_RALT,
		KEY_LEFT,
		KEY_UP,
		KEY_RIGHT,
		KEY_DOWN,
		KEY_INSERT,
		KEY_DELETE,
		KEY_HOME,
		KEY_END,
		KEY_PAGE_UP,
		KEY_PAGE_DOWN,
		KEY_F1,
		KEY_F2,
		KEY_F3,
		KEY_F4,
		KEY_F5,
		KEY_F6,
		KEY_F7,
		KEY_F8,
		KEY_F9,
		KEY_F10,
		KEY_F11,
		KEY_F12,
		KEYS_COUNT = 512
	};
	
	//! @brief Press keyboard button
	void keyPress( int btn );
	//! @brief Release keyboard button
	void keyRelease( int btn );
	
protected:
	friend class Singleton< Keyboard >;
	Keyboard();
	
private:
	bool keys[ KEYS_COUNT ]; //!< State of all keyboard buttons
};

//! @brief Class for mouse controller
//!
//! Hords state of all mouse buttons and current cursor position.
//! Also different function objects can be bound to handle
//! mouse events.
class Mouse : public Singleton< Mouse > {
public:
	enum Button {
		MB_LEFT        = 1L << 0,
		MB_MIDDLE      = 1L << 1,
		MB_RIGHT       = 1L << 2,
		MB_SCROLL_UP   = 1L << 3,
		MB_SCROLL_DOWN = 1L << 4
	};
	
	//! @brief Press mouse button
	void buttonPress( int btn );
	//! @brief Release mouse button
	void buttonRelease( int btn );
	//! @brief Move mouse cursor
	void moveCursor( int xpos, int ypos );
	
protected:
	friend class Singleton< Mouse >;
	Mouse();
	
private:
	int x, y;    //!< Mouse cursor position
	int buttons; //!< Mouse buttons' state
};

#endif // CONTROLLER_H
